package com.wd.home.viewmodel

import android.content.Context
import android.util.Log
import androidx.lifecycle.ViewModel
import com.baidu.ocr.sdk.OCR
import com.baidu.ocr.sdk.OnResultListener
import com.baidu.ocr.sdk.exception.OCRError
import com.baidu.ocr.sdk.model.OcrRequestParams
import com.baidu.ocr.sdk.model.OcrResponseResult
import com.blankj.utilcode.util.ToastUtils
import java.io.File

class FindViewModel :ViewModel() {
    fun getLicenseByOCR(file: String, context: Context) {
        val param = OcrRequestParams()
        param.imageFile = File(file)

        OCR.getInstance(context).recognizeVehicleLicense(
            param, object : OnResultListener<OcrResponseResult> {
                override fun onResult(p0: OcrResponseResult?) {
                    p0?.let {
                        Log.w("OcrRequestParams", it.jsonRes.toString())
                        ToastUtils.showLong(it.jsonRes.toString())
                    }
                }

                override fun onError(p0: OCRError?) {
                    Log.e("OcrRequestParams", p0.toString())
                }
            })
    }

}